<template>
  <div class="perosonal">
    <scroll class="scroll">
      <div class="scrollbox">
        <div class="perleft">
          <el-form ref="form" :model="form" label-width="80px">
            <el-form-item label="用户名" prop="userName">
              <el-input
                v-model="form.userName"
                prefix-icon="el-icon-user"
                disabled
              ></el-input>
            </el-form-item>
            <el-form-item label="账号">
              <el-input
                v-model="form.account"
                prefix-icon="el-icon-notebook-2"
                disabled
              ></el-input>
            </el-form-item>
            <el-form-item label="密码">
              <el-input
                prefix-icon="el-icon-lock"
                v-model="form.passWord"
                disabled
              ></el-input>
            </el-form-item>
            <el-form-item label="签名">
              <el-input
                prefix-icon="el-icon-edit-outline"
                v-model="form.signature"
                disabled
              ></el-input>
            </el-form-item>
            <el-form-item label="出生日期">
              <el-input
                prefix-icon="el-icon-edit-outline"
                v-model="form.date"
                disabled
              ></el-input>
            </el-form-item>
            <el-form-item label="头像">
              <el-image
                style="width: 100px; height: 100px"
                :src="imageUrl"
              ></el-image>
            </el-form-item>
          </el-form>
        </div>
        <div class="perright">
          <el-button type="primary" @click="visible = true">修改档案</el-button>
        </div>
      </div>
    </scroll>
    <modify-file
      v-if="visible"
      @handleFile="handleFile"
      @close="close"
    ></modify-file>
  </div>
</template>
<script>
import ModifyFile from "./ModifyFile"
import request from "../../api/request"
import Scroll from "../../components/scroll/scroll"
import { mapGetters } from "vuex"
export default {
  data() {
    return {
      imageUrl: "",
      form: {
        userName: "",
        account: "",
        passWord: "",
        signature: "",
        photo: "",
        date: "",
      },
      visible: false,
    }
  },
  computed: {
    ...mapGetters(["getAdmin"]),
  },
  components: {
    ModifyFile,
    Scroll,
  },
  created() {
    this.getUserFile()
  },
  methods: {
    // ModifyFile组件中获取到要修改的数据
    async handleFile(data) {
      let res = await request({
        url: "/modify/file",
        data,
        method: "post",
      })
      if (res.status) {
        this.$notify({
          title: "成功",
          message: res.msg,
          type: "success",
        })
        this.visible = false
        this.getUserFile()
        this.$EventBus.$emit("updateUser")
      } else {
        this.$notify.error({
          title: "错误",
          message: res.msg,
        })
      }
    },
    close() {
      this.visible = false
    },
    getUserFile() {
      this.form.userName = this.getAdmin.userName
      this.form.account = this.getAdmin.account
      this.form.passWord = this.getAdmin.passWord
      this.form.signature =
        this.getAdmin.signature || "这个家伙很懒，没有写签名"
      this.form.date = this.getAdmin.date || "暂无数据"
      this.imageUrl = this.getAdmin.photo || ""
    },
  },
}
</script>
<style lang="scss" scoped>
.perosonal {
  height: calc(100% - 50px);
}
.perosonal .el-form {
  margin: 10px;
}
.scrollbox {
  display: flex;
  padding: 20px;
  box-sizing: border-box;
}
.perosonal .perleft {
  width: 80%;
  border: 1px solid rgb(190, 189, 189);
}
.perosonal .perright {
  width: calc(20% - 3px);
  border: 1px solid rgb(190, 189, 189);
  border-left: none;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>
